package main

import "fmt"

func pivotIndex(nums []int) int {
	if len(nums) == 0 {
		return -1
	}
	sums := make([]int, len(nums))
	sums[0] = nums[0]

	for i := 1; i < len(nums); i++ {
		//fmt.Print(i)
		sums[i] = sums[i-1] + nums[i]
	}
	if 0 == sums[len(sums)-1]-nums[0] {
		return 0
	}
	for i := 1; i < len(sums); i++ {
		if sums[i-1] == sums[len(sums)-1]-sums[i-1]-nums[i] {
			fmt.Println(sums[i-1], nums[i])
			return i
		}
	}
	fmt.Print(sums)
	return -1
}

func main() {
	//nums := []int{1, 7, 3, 6, 5, 6}
	nums := []int{-1, -1, -1, 0, 1, 1}
	c := pivotIndex(nums)
	fmt.Println(c)
}
